package com.c.service;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.druid.pool.DruidDataSource;
import com.c.dao.exampleDao;

import cn.hutool.core.date.DateTime;
import cn.hutool.db.Entity;
import cn.hutool.db.SqlRunner;

@Service
@Transactional
public class exampleService {

	@Autowired
	private exampleDao eDao;

	@Autowired
	private DruidDataSource ds;
	
	@Transactional(rollbackFor = Exception.class)
	public List getList() {
		return eDao.getListUseHuTool();
	}
	
//	@Transactional()
	@Transactional(rollbackFor = Exception.class)
	public void testTran() throws Exception {
		SqlRunner runner = SqlRunner.create(ds);
		Entity log1 = Entity.create("log").set("create_time", new DateTime(new Date()).toString())
				.set("operation", "a").set("operator", "管理员");
		runner.insert(log1);
		
		try{ int i =1/0;}catch(Exception a){throw new RuntimeException();}
		
		
		Entity log2 = Entity.create("log").set("create_time", new DateTime(new Date()).toString())
				.set("operation", "b").set("operator", "管理员");
		runner.insert(log2);
	}
}
